package algorithm

import (
	"github.com/bgmp/config"
	"github.com/bgmp/middleware"
	"github.com/bgmp/model"
	"github.com/bgmp/service"
	"github.com/gin-gonic/gin"
)

func (b Base) GetPredict(c *gin.Context, req *GetPredictRequest) *GetPredictResponse {
	userId := middleware.GetUserId(c)
	predicts := model.GetPredicts(config.DB, userId, req.Time, req.Number)
	var results []service.PredictResult
	for _, predict := range predicts {
		result := service.PredictResult{
			Value: predict.Value,
			Time:  predict.PredictAt.Unix(),
		}
		results = append(results, result)
	}
	return &GetPredictResponse{
		Predicts: results,
	}
}

type GetPredictRequest struct {
	Time   model.Time `json:"time"`
	Number int        `json:"number"`
}

type GetPredictResponse struct {
	Predicts []service.PredictResult `json:"predicts"`
}
